package com.randomrpg.game

/**
 * Classes of the game
 */

@serializable @SerialVersionUID(666)
abstract case class RPGClass(val name: String, val attributes: Attributes, val life: Int) {
  val mp = 0

  def levelUp(player: Player): Unit = {
    player.level += 1
    player.maxLife += (life + player.con) / 2
    player.life = player.maxLife
    player.exp = 0
  }
}

case class Warrior() extends RPGClass("Warior", new Attributes(10, 6, 8, 2, 4), 18) {
  override def levelUp(player: Player): Unit = {
    player.str += 1
    player.con += 1
    if(player.str % 2 == 0) player.dex += 1;
    super.levelUp(player)
  }
}

case class Cleric() extends RPGClass("Cleric", new Attributes(8, 4, 6, 2, 10), 16) {
  override val mp = 10
  
  override def levelUp(player: Player): Unit = {
    player.will += 1
    player.str += 1
    if(player.will % 2 == 0) player.con += 1
    player.maxMp += player.int
    player.mp = player.maxMp
    super.levelUp(player)
  }
}

case class Rogue() extends RPGClass("Rogue", new Attributes(8, 10, 6, 4, 2), 14) {
  override def levelUp(player: Player): Unit = {
    player.dex += 1
    player.str += 1
    if(player.dex % 2 == 0) player.con += 1
    super.levelUp(player)
  }
}

case class Mage() extends RPGClass("Mage", new Attributes(4, 8, 6, 10, 2), 12) {
  override val mp = 20
  
  override def levelUp(player: Player): Unit = {
    player.int += 1
    player.dex += 1
    if(player.int % 2 == 0) player.con += 1
    player.maxMp += player.int
    player.mp = player.maxMp
    super.levelUp(player)
  }
}

object ClassList {
  val desc = Map("Warrior" -> "High damage, life",
                 "Rogue"   -> "High damage, critical, evade. Low life",
                 "Mage"    -> "High evade. Low damage, life. Magic",
                 "Cleric"  -> "Average damage, life. Heal")
}